/**********************************************************************************
 * Code license:  GNU General Public License v3                                   *
 * Main page:     https://code.google.com/p/library-cross-platform/               *
 * Issue tracker: https://code.google.com/p/library-cross-platform/issues/list    *
***********************************************************************************/
package library.util;

public class Hash {
	
  public Hash() {
  }
  
  
  public long getStringHashValue(String val) {
    return getStringHashValue(val.toCharArray());
  }
  
  public long getStringHashValue(final char[] val) {
    int max_index  = val.length;
    int count      = 0;
    long ret_value = 0;
	    
    while(count < max_index && val[count] != '\0') {
      ret_value += getHashValue(val[count], ret_value);
      count ++;
    }
    return ret_value;
  }

  public long getStringHashValue(StringBuilder val) {
    int max_index  = val.length();
    int count      = 0;
    long ret_value = 0;
    
    while(count < max_index && val.charAt(count) != '\0') {
      ret_value += getHashValue(val.charAt(count), ret_value);
      count ++;
    }
    return ret_value;
  }

  protected long getHashValue(char val, long base) {
    long ret_value = 1;
    long offset    = val - 'a';
    ret_value = ret_value << offset;
    ret_value = base | ret_value;
    return ret_value;
  }
}
